package com.cn.crmsystem.service.approveService.impl;

import com.cn.crmsystem.mapper.approveMapper.ReimbursementMapper;
import com.cn.crmsystem.pojo.*;
import com.cn.crmsystem.service.approveService.ReimbursementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ReimbursementImpl implements ReimbursementService{
	@Autowired ReimbursementMapper reimbursementMapper;
	//查询审核人
	@Override
	public ResultJson selectLeader(Integer userid) {
		ResultJson resultJson=new ResultJson();/*
		String code;
		String msg;
		Integer c=reimbursementMapper.selectleaderId(userid);
		User user= new User();
		user=reimbursementMapper.selectleader(c);
		if(c>0&&user!=null){
			code="200";
			resultJson.getSuccess(code,user);
		}else{
			msg="失  败";
			resultJson.getFail(msg);
		}
		*/return resultJson;
	}
	//插入
	@Override
	public ResultJson ReimbursementInsert(Reimbursement reimbursement, Integer leader) {
		ResultJson resultJson=new ResultJson();/*
		String code;
		String msg;
		try{
			Integer c=reimbursementMapper.InsertReimbursement(reimbursement);
			Integer reimbursementid=reimbursement.getReimbursement_Id();
			Integer type=1;
			if(c>0) {
				Integer d=reimbursementMapper.InsertApprove(leader,reimbursementid,type);
				if (d>0){
					code="200";
					msg = "成功";
					resultJson.getSuccess(msg,code);
				}else{
					msg = "失 败";
					resultJson.getSuccess(msg);
				}
			}else{
				msg = "失败";
				resultJson.getSuccess(msg);
			}
		}catch (Exception e){
			msg=e.getMessage();
			resultJson.getFail(msg);
		}
		*/return resultJson;
	}
	//查询报销列表
	@Override
	public ResultJson SelectMyReimbursement(Integer userid,String method) {
		ResultJson resultJson=new ResultJson();/*
		Map<String,Object> map=new HashMap<>();
		String msg;
		List<Approve> list=new ArrayList<>();
		if(method=="0"){
			list=reimbursementMapper.selectMYReimbursement(userid);
			if(list!=null) {
			map.put("我发出报销列表",list);
			resultJson.getSuccess("成功",map);
		}else{
			resultJson.getSuccess("失败");
		}
		}else{
			list=reimbursementMapper.selectApproveReimbursement(userid);
			if(list!=null) {
				map.put("我审核报销列表",list);
				resultJson.getSuccess("成功",map);
			}else{
				resultJson.getSuccess("失败");
			}
		}
		*/return resultJson;
	}
	//删除
	@Override
	public ResultJson DeleteReimbursement(Integer appid) {
		ResultJson resultJson=new ResultJson();/*
		String code;
		String msg;
		if(reimbursementMapper.DeleteApprove(appid)>0) {
			int reimbursement=reimbursementMapper.Reimbursementid(appid);
			if(reimbursementMapper.DeleteReimbursement(reimbursement)>0){
				code="200";
				msg = "成功";
				resultJson.getSuccess(msg,code);
			}else{
				msg="失败";
				resultJson.getSuccess(msg);
			}
		}else{
			msg="失败";
			resultJson.getSuccess(msg);
		}
		*/return resultJson;
	}
	//更新
	@Override
	public ResultJson UpdateReimbursement(Integer appid,Integer state) {
		ResultJson resultJson=new ResultJson();/*
		String code;
		String msg;
		if(reimbursementMapper.UpdateReimbursement(appid,state)>0) {
			code="200";
			msg = "成功";
			resultJson.getSuccess(msg,code);
		}else{
			msg="失败";
			resultJson.getSuccess(msg);
		}
		*/return resultJson;
	}
	//条件查询
	@Override
	public ResultJson SelectConditionReimbursement(Integer userid, String method, String state) {
		ResultJson resultJson=new ResultJson();/*
		Map<String,Object> map=new HashMap<>();
		Approve ap=new Approve();
		List<Approve> condtion=new ArrayList<>();
		if(method=="0"){
			condtion=reimbursementMapper.selectMyCondition(userid,state);
			if(condtion!=null) {
				map.put("我发出报销列表",condtion);
				resultJson.getSuccess("成功",map);
			}else{
				resultJson.getSuccess("失败");
			}
		}else{
			condtion=reimbursementMapper.selectApproveCondition(userid,state);
			if(condtion!=null) {
				map.put("我审核报销列表",condtion);
				resultJson.getSuccess("成功",map);
			}else{
				resultJson.getSuccess("失败");
			}
		}
		*/return resultJson;
	}
}
